package com.link.base.task;

import com.link.base.base.wechat.service.WxSendBatchService;
import com.link.base.core.basic.config.xxljob.BaseLinkJobHandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@JobHandler(value = "wxSendBatchJobHandler") //job名称，用于在注册中心注册job，
@Component
public class TaskWxSendBatch extends BaseLinkJobHandler {

    @Resource
    private WxSendBatchService wxSendBatchService;

    /**
     * 定时发送图文消息
     *
     * @author lujiang
     * @date 2019-05-27
     */
    @Override
    public ReturnT<String> execute(String params) throws Exception {
        try {
            //XxlJobLogger 打印的日志会体现在调度中心的执行日志中
            XxlJobLogger.log("XXL-JOB, Hello couponsJobHandler");
            //设置登录信息
            super.setLogin(params);
            //执行自己的业务代码
            wxSendBatchService.fixedTimeSendArticle();
            //返回成功
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log(e.getMessage());
            return ReturnT.FAIL;
        }
    }
}

